<?php

namespace App\Services;


use App\Models\WorkWechatUser;
use EasyWeChat\Factory;

class WorkWechatContactService
{
    /**
     * 企业微信通讯录管理
     */

    private $corp_id = '';
    private $contacts = null;

    public function __construct()
    {
        $config = config('wechat.work.contact');
        $this->corp_id = $config['corp_id'];
        $this->contacts = Factory::work($config);
    }

    public function getUser($userid)
    {
        $res = $this->contacts->user->get($userid);

        WorkWechatUser::query()->create([
            'corp_id' => $this->corp_id, // 企业ID，满足多企业场景需求
            'userid' => $res['userid'],
            'name' => $res['name'],
            'avatar' => $res['avatar'],
            'department' => $res['department'], // 所属部门列表。列表项为部门ID，32位整型
            'userinfo' => $res, // 拉取的全部信息，todo 后续完善扩展
        ]);

    }

}
